import delimited "C:\replication\deathideas_data_replication.csv"

*Keep non-appropriations bills
keep if approps==0 
*Keep first versions of sections proposed in the same term
keep if not_first==0

*Remove freshman (including count retains senators who previously served in House)
drop if seniority==1 & count_y==1

*Drops delegates
drop if icpsr==0

*drop other delegates or those who briefly served
drop if committee_leader==.

*Create DV for death based on if identical section is reintroduced
gen death_identical = death
replace death_identical=1 if reintro_identical==0 & death==0

*Create DV for death based on if near identical section is reintroduced
gen death_nearidentical = death
replace death_nearidentical=1 if reintro_near_identical==0 & death==0

gen logmajor_lag = log(lag_major)
gen log_seccomplexity = log(sec_complexity)

gen chair = 0
replace chair = 1 if committee_leader==1 & majority==1
replace chair = 1 if chref==1

gen ranking = 0
replace ranking = 1 if committee_leader==1 & majority==0
replace ranking = 1 if rankref==1

rename v24 congress2

*Replace lagged major codes that are missing from merge
*Major code 23 for 107th
replace logmajor_lag=log(20) if v1==134418 | v1==128091 | v1==131406 | v1==132445 | v1==133638 | v1==133656 | v1==135329 | v1==135956 | v1==147411 | v1==149117 
replace major=23 if v1==134418 | v1==128091 | v1==131406 | v1==132445 | v1==133638 | v1==133656 | v1==135329 | v1==135956 | v1==147411 | v1==149117
*Major code 23 for 108th
replace logmajor_lag=log(20) if v1==162475 | v1==166238 | v1==171262 | v1==171263 | v1==171264 | v1==171265 | v1==171266 | v1==171267 | v1==171268 | v1==176639
replace major=23 if v1==134418 | v1==128091 | v1==131406 | v1==132445 | v1==133638 | v1==133656 | v1==135329 | v1==135956 | v1==147411 | v1==149117
*Major code 23 for 109th
replace logmajor_lag=log(6) if v1==226148 | v1==230959 | v1==257427 
replace major=23 if v1==226148 | v1==230959 | v1==257427
*12 in 109th
replace logmajor_lag=log(2610) if v1==238275 
replace major=12 if v1==238275 
*6 in 110th
replace logmajor_lag=log(1669) if v1==265815 
replace major=6 if v1==265815 
*23 in 111th
replace logmajor_lag=log(3) if v1==266542 | v1==284669 
replace major=23 if v1==266542 | v1==284669 
*17 in 111th
replace logmajor_lag=log(803) if v1==268256 | v1==268258 | v1==268259 | v1==268260
replace major=17 if v1==268256 | v1==268258 | v1==268259 | v1==268260
*99 in 113th
replace logmajor_lag=log(70) if congress2==113 & logmajor_lag==. & major==99


*Replace missing Shelia Jackson Lee data
replace les_benchmarklag=2 if icpsr==29573 & congress2==111
*Replace missing Jim Sensenbrenner data
replace les_benchmarklag=1 if icpsr==14657 & congress2==107
*Replace missing Delahunt data
replace les_benchmarklag=2 if icpsr==29731 & congress2==111
*Replace missing Herseth data
replace les_benchmarklag=3 if icpsr==20349 & congress2==111
*Replace missing C.W. Young data
replace les_benchmarklag=1 if icpsr==13047 & congress2==111

*Replace missing cosponsor data
replace cosponsr = 1 if billid=="113hr1232"
replace cosponsr = 2 if billid=="113s2189"
replace cosponsr = 17 if billid=="113s2692"
replace cosponsr = 11 if billid=="113s1803"
replace cosponsr = 22 if billid=="113s195"
replace cosponsr = 18 if billid=="113hr1566"

*Drop 103rd data, where there is no lagged data
drop if logmajor_lag==.

*Check for missing data
mdesc death committee_leader mref party_leader ideodist_floormedian next_term2 companion momentum change_divgov change_gridlockpp logmajor_lag cosponsr seniority majority bills_sponsored sec_complexity les_benchmarklag senate bill_section_count
*Sanford and Walberg are missing for the les_benchmarklag. They have breaks in their tenure, so not missing data.

***Descriptive statistics
*% of deaths (included in Table 2)
tab death if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & reintro_match<10
tab death_identical if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & reintro_match<10
tab death_nearidentical if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & reintro_match<10
*Deaths if bill is longer than 1 section (included in Table 2)
tab death if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & reintro_match<10 & bill_sec>1

sort congress2 icpsr
by congress2 icpsr: egen idea_count = count(death) if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & reintro_match<10
*Count of sections proposed, by member-term
sum idea_count, detail

***Figure 2 and 3 Code***
collapse (sum) death (count) death_identical if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & reintro_match<10, by(congress2 icpsr)
rename death_identical sec_count
gen perc_die = death/sec_count
set scheme plotplain
graph box perc_die, over(congress2) ytitle(Proportion of Measures Not Reintroduced) b1title(Congress) ylabel(,nogrid)
ylabel(0(1)6,nogrid)
histogram perc_die, width(0.02) percent xtitle(% of Members' Legislative Portfolios Not Reintroduced) xlabel(,nogrid) ylabel(0(1)6,nogrid)

***Main section-level model
xtset icpsr
xtreg death chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, re vce(robust)
*P-values for Bonferroni correction
matrix list r(table) 

***Figure 4***
margins, at(chref=1 rankref=0 mref=1 chair=1 ranking=0 companion=0 momentum=0 change_divgov=0 majority=1 next_term2=1 companion=0 senate=0) atmeans saving(m_1, replace)
margins, at(chref=0 rankref=0 mref=1 chair=0 ranking=0 companion=0 momentum=0 change_divgov=0 majority=1 next_term2=1 companion=0 senate=0) atmeans saving(m_2, replace)
margins, at(chref=0 rankref=0 mref=0 chair=0 ranking=0 companion=0 momentum=0 change_divgov=0 majority=1 next_term2=1 companion=0 senate=0) atmeans saving(m_3, replace)
margins, at(chref=0 rankref=0 mref=0 chair=1 ranking=0 companion=0 momentum=0 change_divgov=0 majority=1 next_term2=1 companion=0 senate=0) atmeans saving(m_4, replace)
set scheme plotplain
combomarginsplot12 m_3 m_2 m_4 m_1, label("Not On Referred Committee" "On Referred Committee" "Chair - Not On Referred Committee" "Chair - On Referred Committee") xtitle("Predicted Probability") title("") recast(scatter) horizontal ytitle("") xlabel(0.5(0.05)1 ,nogrid) ylabel(,nogrid) 
combomarginsplot12 m_3 m_4 m_2 m_1, label("Not On Referred Committee" "Chair - Not On Referred Committee" "On Referred Committee" "Chair - On Referred Committee") xtitle("Predicted Probability") title("") recast(scatter) horizontal ytitle("") xlabel(0.5(0.05)1 ,nogrid) ylabel(,nogrid) 

***Robustness checks included in Supplementary Materials***
*Identical
xtreg death_identical chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, vce(robust)
*Near identical
xtreg death_nearidentical chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, vce(robust)
*esttab sec_identical sec_nearidentical using "\Users\jgelman\Desktop\identical_robustness", cells(b(fmt(2) star) se(fmt(2) par)) star(* 0.05 ** 0.01) r2 staraux varlabels(next_term2 "Returning to Congress" les_benchmarklag "Legislative Effectivness" majority "Majority Party" companion "Companion" change_divgov "Change in Divided Gov't" committee_leader "Committee Leader" party_leader "Party Leader" momentum "Advanced" change_gridlockpp "Change in Gridlock Interval" cosponsr "# of Cosponsors" seniority "Terms Served" ideodist_floormedian "Ideological Extremity" senate "Senate" lag_major "Previously Enacted Sections" bills_sponsored "Number of Bills Sponsored" _cons "Constant") title("Test 1") rtf replace
*House only
xtreg death chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10 & senate==0, vce(robust)
*Senate only
xtreg death chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10 & senate==1, vce(robust)
*More than 1 section
xtreg death chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10 & bill_section_count>1, vce(robust)

*Pooled, cluster robust standard errors
reg death chref rankref mref chair ranking majority ideodist_floormedian next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority  bills_sponsored les_benchmarklag senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, vce(cluster icpsr)
reg death_identical chref rankref mref chair ranking majority ideodist_floormedian next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority  bills_sponsored les_benchmarklag senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, vce(cluster icpsr)
reg death_nearidentical chref rankref mref chair ranking majority ideodist_floormedian next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority  bills_sponsored les_benchmarklag senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, vce(cluster icpsr)

*Random intercept with cluster robust standard errors
xtreg death chref rankref mref chair ranking majority ideodist_floormedian next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority  bills_sponsored les_benchmarklag senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, re vce(cluster icpsr)
xtreg death_idential chref rankref mref chair ranking majority ideodist_floormedian next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority  bills_sponsored les_benchmarklag senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, re vce(cluster icpsr)
xtreg death_nearidential chref rankref mref chair ranking majority ideodist_floormedian next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority  bills_sponsored les_benchmarklag senate log_seccomplexity bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0 & congress2>103 & reintro_match<10, re vce(cluster icpsr)

clear

***Bill level DVs***
import delimited "C:\replication\deathideas_billdata_replication.csv"

gen perc_different = (bill_section - reintro_identical)/bill_section
gen perc_neardifferent = (bill_section - reintro_near_identical)/bill_section

*Identical all sections die
gen all_died_identical = all_died
replace all_died_identical=1 if reintro_identical==0

*Near identical all sections die
gen all_died_nearidentical = all_died
replace all_died_nearidentical=1 if reintro_near_identical==0

*Table 2 and preceding paragraph
*% of sections not reintroduced
sum perc_died if tariff==0 & post_office==0 & gold_medal==0 & coins==0 & facility==0, detail
sum perc_died if tariff==0 & post_office==0 & gold_medal==0 & facility==0 & bill_section_count>1, detail 

*% of bills where all sections die 
tab all_died if tariff==0 & post_office==0 & gold_medal==0 & coins==0 & facility==0
tab all_died if tariff==0 & post_office==0 & gold_medal==0 & coins==0 & facility==0 & bill_section>1

xtset icpsr
xtreg perc_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(robust)
matrix list r(table) 
xtreg all_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(robust)
matrix list r(table) 

*% robustness checks
*Identical
xtreg perc_different chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(robust)
*Near identical
xtreg perc_neardifferent chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0, vce(robust)
*esttab sec_identical sec_nearidentical using "\Users\jgelman\Desktop\identical_robustness", cells(b(fmt(2) star) se(fmt(2) par)) star(* 0.05 ** 0.01) r2 staraux varlabels(next_term2 "Returning to Congress" les_benchmarklag "Legislative Effectivness" majority "Majority Party" companion "Companion" change_divgov "Change in Divided Gov't" committee_leader "Committee Leader" party_leader "Party Leader" momentum "Advanced" change_gridlockpp "Change in Gridlock Interval" cosponsr "# of Cosponsors" seniority "Terms Served" ideodist_floormedian "Ideological Extremity" senate "Senate" lag_major "Previously Enacted Sections" bills_sponsored "Number of Bills Sponsored" _cons "Constant") title("Test 1") rtf replace
*House only
xtreg perc_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0 & senate==0, vce(robust)
*Senate only
xtreg perc_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0 & senate==1, vce(robust)
*More than 1 section
xtreg perc_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0 & bill_section>1, vce(robust)

*All died robustness checks
xtreg all_died_identical chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(robust)
*Near identical
xtreg all_died_nearidentical chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & gold_medal==0 & coin==0 & facility==0, vce(robust)
*esttab sec_identical sec_nearidentical using "\Users\jgelman\Desktop\identical_robustness", cells(b(fmt(2) star) se(fmt(2) par)) star(* 0.05 ** 0.01) r2 staraux varlabels(next_term2 "Returning to Congress" les_benchmarklag "Legislative Effectivness" majority "Majority Party" companion "Companion" change_divgov "Change in Divided Gov't" committee_leader "Committee Leader" party_leader "Party Leader" momentum "Advanced" change_gridlockpp "Change in Gridlock Interval" cosponsr "# of Cosponsors" seniority "Terms Served" ideodist_floormedian "Ideological Extremity" senate "Senate" lag_major "Previously Enacted Sections" bills_sponsored "Number of Bills Sponsored" _cons "Constant") title("Test 1") rtf replace
*House only
xtreg all_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0 & senate==0, vce(robust)
*Senate only
xtreg all_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0 & senate==1, vce(robust)
*More than 1 section
xtreg all_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0 & bill_section>1, vce(robust)

*Random intercept with cluster robust standard errors
xtreg perc_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(cluster icpsr)
reg perc_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(cluster icpsr)
xtreg all_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(cluster icpsr)
reg all_died chref rankref mref chair ranking majority next_term2 companion momentum cosponsr change_divgov change_gridlockpp logmajor_lag seniority bills_sponsored les_benchmarklag ideodist_floormedian senate bill_section_count if tariff==0 & post_office==0 & coin==0 & gold_medal==0 & facility==0, vce(cluster icpsr)

clear

***Do deaths predict new introductions analysis***
import delimited "C:\replication\member_intros_deaths_R&R_replication.csv"

gen chair = 0
replace chair = 1 if committee_leader==1 & majority==1
replace chair = 1 if chref==1 & chair==0

gen ranking = 0
replace ranking = 1 if committee_leader==1 & majority==0
replace ranking = 1 if rankref==1 & ranking==0

*Drop delegates
drop if icpsr==0
drop if congress==103

xtset icpsr
xtnbreg new_intros death enact_lastterm chref mref rankref chair ranking ideodist majority les_benchmarklag senate seniority bills_introduced i.congress, fe

margins, at(death=(1(10)80) chref=1 rankref=0 mref=1 ranking=0 majority=1 senate=0) atmeans vsquish
margins, at(death=21 chref=1 rankref=0 mref=1 ranking=0 majority=1 senate=0) atmeans vsquish
margins, at(death=21 chref=0 rankref=1 mref=1 ranking=0 majority=0 senate=0) atmeans vsquish
margins, at(death=21 chref=0 rankref=0 mref=1 ranking=0 majority=1 senate=0) atmeans vsquish
margins, at(death=21 chref=0 rankref=0 mref=0 ranking=0 majority=1 senate=0) atmeans vsquish

clear
